package info.webest.media;

import info.webest.media.category.Category.CategoryFolder;
import info.webest.media.category.Category.StorageType;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class Options {

	public static boolean CHOICE_MODE_MULTIPLE = false;

	public enum ScreenTheme {
		THEME_DARK, THEME_LIGHT
	};

	public enum ScreenOrientation {
		SCREEN_PORTRAIT, SCREEN_LANDSCAPE, SCREEN_AUTO
	};

	public static final String SHOW_WHEN_LOCKED = "ShowWhenLocked";
	public static final String KEEP_NOTIFICATION = "KeepNotification";
	public static final String HEADSET_PLUG = "HeadsetPlug";
	public static final String HEADSET_UNPLUG = "HeadsetUnplug";
	public static final String HEADSET_BUTTON = "HeadsetButton";
	public static final String VOLUME_INDICATOR = "VolumeIndicator";

	public static final String THEME = "Theme";
	public static final String VOLUME_CONTROL = "VolumeControl";
	public static final String EQUALIZER = "Equalizer";
	public static final String FAST_SCROLL = "FastScroll";
	public static final String FONT_SIZE = "FontSize";
	public static final String LINE_SPACING = "LineSpacing";

	public static final String SHOW_FOLDER_SIZE = "ShowFolderSize";
	public static final String COUNT_FOLDER_ELEMENTS = "CountFolderElements";
	public static final String SHOW_FILE_EXT = "ShowFileExt";
	public static final String SHOW_FILE_SIZE = "ShowFileSize";
	public static final String SHOW_DURATION = "ShowDuration";

	public static final String HOME_STORAGE = "HomeStorage";
	public static final String HOME_FOLDER = "HomeFolder";

	public static boolean ShowWhenLocked = false;
	public static boolean KeepNotification = true;
	public static boolean HeadsetPlug = false;
	public static boolean HeadsetUnplug = true;
	public static boolean HeadsetButton = true;
	public static boolean VolumeIndicator = true;

	public static ScreenTheme Theme = ScreenTheme.THEME_DARK;
	public static ScreenOrientation Orientation = ScreenOrientation.SCREEN_AUTO;
	public static boolean VolumeControl = true;
	public static boolean Equalizer = true;
	public static boolean FastScroll = true;
	public static int FontSize = 16;
	public static int LineSpacing = 4;

	public static boolean ShowFolderSize = true;
	public static boolean CountFolderElements = true;
	public static boolean ShowFileExt = true;
	public static boolean ShowFileSize = false;
	public static boolean ShowDuration = false;

	public static StorageType HomeStorage = StorageType.INTERNAL_STORAGE;
	public static CategoryFolder HomeFolder = CategoryFolder.FOLDER_AUDIO_MUSIC;

	public static void getPreferences(Context context) {

		String s = null;
		SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(context);

		// Common
		ShowWhenLocked = prefs.getBoolean(SHOW_WHEN_LOCKED, ShowWhenLocked);
		KeepNotification = prefs
				.getBoolean(KEEP_NOTIFICATION, KeepNotification);
		HeadsetPlug = prefs.getBoolean(HEADSET_PLUG, HeadsetPlug);
		HeadsetUnplug = prefs.getBoolean(HEADSET_UNPLUG, HeadsetUnplug);
		HeadsetButton = prefs.getBoolean(HEADSET_BUTTON, HeadsetButton);
		VolumeIndicator = prefs.getBoolean(VOLUME_INDICATOR, VolumeIndicator);

		// User Interface
		s = prefs.getString("ScreenOrientation", "Auto");
		if (s.equals("Portrait")) {
			Orientation = Options.ScreenOrientation.SCREEN_PORTRAIT;

		} else if (s.equals("Landscape")) {
			Orientation = Options.ScreenOrientation.SCREEN_LANDSCAPE;

		} else if (s.equals("Auto")) {
			Orientation = Options.ScreenOrientation.SCREEN_AUTO;
		}

		s = prefs.getString("ScreenTheme", "Dark");
		if (s.equals("Dark")) {
			Theme = ScreenTheme.THEME_DARK;

		} else if (s.equals("Light")) {
			Theme = ScreenTheme.THEME_LIGHT;
		}

		VolumeControl = prefs.getBoolean(VOLUME_CONTROL, VolumeControl);
		Equalizer = prefs.getBoolean(EQUALIZER, Equalizer);
		FastScroll = prefs.getBoolean(FAST_SCROLL, FastScroll);
		s = prefs.getString(FONT_SIZE, "" + FontSize);
		FontSize = Integer.valueOf(s);
		s = prefs.getString(LINE_SPACING, "" + LineSpacing);
		LineSpacing = Integer.valueOf(s);

		ShowWhenLocked = prefs.getBoolean(SHOW_WHEN_LOCKED, ShowWhenLocked);
		KeepNotification = prefs
				.getBoolean(KEEP_NOTIFICATION, KeepNotification);

		// Files and Folders
		ShowFolderSize = prefs.getBoolean(SHOW_FOLDER_SIZE, ShowFolderSize);
		CountFolderElements = prefs.getBoolean(COUNT_FOLDER_ELEMENTS,
				CountFolderElements);
		ShowFileExt = prefs.getBoolean(SHOW_FILE_EXT, ShowFileExt);
		ShowFileSize = prefs.getBoolean(SHOW_FILE_SIZE, ShowFileSize);
		ShowDuration = prefs.getBoolean(SHOW_DURATION, ShowDuration);

		// cbTaskMode = Integer.parseInt(prefs.getString("task_mode", "1"));

		HomeStorage = StorageType.fromInteger(prefs.getInt(HOME_STORAGE,
				StorageType.toInteger(HomeStorage)));
		HomeFolder = CategoryFolder.fromInteger(prefs.getInt(HOME_FOLDER,
				CategoryFolder.toInteger(HomeFolder)));

	}

	public static int getThemeId() {
		int themeId = 0;

		switch (Theme) {
		case THEME_DARK:
			themeId = R.style.ThemeDark;
			break;

		case THEME_LIGHT:
			themeId = R.style.ThemeLight;
			break;
		}

		return themeId;
	}

}
